import java.util.Scanner;

import static java.lang.System.exit;

public class Main {

    public static void menu() {
        System.out.println("*************************");
        System.out.println("**** 1.add    2.find ****");
        System.out.println("**** 3.delete 4.show ****");
        System.out.println("**** 5.size   0.exit ****");
        System.out.println("*************************");

    }
    public static void menuAdd(MyArrayList myArrayList) {
        System.out.println("*********************************");
        System.out.println("**** 1.默认尾插  2.指定位置插入 ****");
        System.out.println("*********************************");
        Scanner scanner = new Scanner(System.in);
        int input = scanner.nextInt();
        switch (input) {
            case 1: {System.out.println("请输入要尾插的数据");
                     int input1 = scanner.nextInt();
                     myArrayList.add(input1);
                     break;
            }
            case 2:{System.out.println("请输入要插入的位置和数据");
                int pos = scanner.nextInt();
                int data = scanner.nextInt();
                myArrayList.add(pos,data);
                break;
            }
            default:
                System.out.println("选择错误，已返回主菜单");
                break;
        }
    }
    public static void menuFind(MyArrayList myArrayList) {
        System.out.println("********************************************");
        System.out.println("**** 1.查找元素的位置     2.查找某位置的元素 ****");
        System.out.println("**** 3.查找某元素是否存在                  ****");
        System.out.println("********************************************");
        System.out.print("请选择你的操作>:");
        Scanner scanner = new Scanner(System.in);
        int input = scanner.nextInt();
        switch (input) {
            case 1: {System.out.print("请输入要查找的元素：");
                int input1 = scanner.nextInt();
                int tmp = myArrayList.indexOf(input1);
                System.out.println(tmp==-1?input1+"找不到":input1+"下标为："+tmp);
                break;
            }
            case 2:{System.out.print("请输入要查找的下标：");
                int pos = scanner.nextInt();
                int ret = myArrayList.get(pos);
                System.out.println(pos+"下标的元素为："+ret);
                break;
            }
            case 3:{
                System.out.print("请输入要检查元素：");
                int toFind = scanner.nextInt();
                boolean bool = myArrayList.contains(toFind);
                System.out.println(bool==true?toFind+"存在":toFind+"不存在");
                break;
            }
            default:
                System.out.println("选择错误，已返回主菜单");
                break;
        }
    }

    public static void main(String[] args) {
        MyArrayList myArrayList = new MyArrayList();
        myArrayList.add(1);
        myArrayList.add(2);
        myArrayList.add(3);
        myArrayList.add(4);
        myArrayList.add(5);
        myArrayList.add(6);
        myArrayList.add(7);
        while(true) {

            Scanner scanner = new Scanner(System.in);
            menu();
            System.out.print("请选择你的操作>:");
            int input = scanner.nextInt();
                switch (input) {
                    case 1:
                        System.out.println("你已选择插入操作！");
                        menuAdd(myArrayList);
                        break;
                    case 2:
                        System.out.println("你已选择查找操作");
                        menuFind(myArrayList);
                        break;
                    case 3:
                        System.out.print("当前顺序表存在的元素：");
                        myArrayList.show();
                        System.out.print("请输入你要删除的元素：");
                        int key = scanner.nextInt();
                        myArrayList.delete(key);
                        break;
                    case 4:
                        System.out.println("你已选择打印顺序表操作！");
                        myArrayList.show();
                        break;
                    case 5:
                        System.out.print("查看顺序表当前大小，");
                       int size = myArrayList.size();
                        System.out.println("顺序表当前大小为："+size);
                        break;
                    case 0:
                        System.out.println("你已选择退出操作：");
                        exit(-1);
                    default:
                        System.out.println("选择错误！重新选择");
                        break;
                }
            }


        }






}
